package com.zhiqianbao.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhiqianbao.R;
import com.zhiqianbao.entity.ContaciInfo;

import java.util.List;

/**
 * Created by 刘子龙
 */
public class FamilyLinkmanList2Adapter extends BaseAdapter {
    private LayoutInflater inflater;
    private List<ContaciInfo.DataBean.UserContactsBean> list;
    private Activity ctx;

    public FamilyLinkmanList2Adapter(Activity context, List<ContaciInfo.DataBean.UserContactsBean> list) {
        this.ctx = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }



    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ListItemView listItemView = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.list_item_family_linkman2, null);
            listItemView = new ListItemView();

            listItemView.contact_people_relation = (TextView)convertView.findViewById(R.id.contact_people_relation);
            listItemView.contact_people_name = (TextView)convertView.findViewById(R.id.contact_people_name);
            listItemView.contact_people_phone = (TextView)convertView.findViewById(R.id.contact_people_phone);
            convertView.setTag(listItemView);
        } else {
            listItemView = (ListItemView) convertView.getTag();
        }

        String tel = list.get(position).getPhone();
        String name = list.get(position).getName();
        String relation = list.get(position).getRelation();
        listItemView.contact_people_name.setText(name);
        listItemView.contact_people_relation.setText(relation);
        listItemView.contact_people_phone.setText(tel);

        return convertView;
    }

    private final class ListItemView {
        public TextView contact_people_relation;
        public TextView contact_people_name;
        public TextView contact_people_phone;
    }

}
